package com.bwhx.eruler.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.Ruler;
import com.bwhx.eruler.bean.Staff;
import com.bwhx.eruler.service.StaffService;
/**
 * 员工管理，销售员管理、库管管理
 * 已废弃
 * @author Cuilitang
 *
 */
@Deprecated
public class StaffController extends BaseController {
	
	@Autowired
	StaffService staffService;
	
	@ResponseBody
	//@RequestMapping(value = "/page.staffList.ashx")
	 public Map staffList(Integer page,Integer rows,Staff s, @RequestBody String b) {
		 log.info(b);
		//每页的开始记录
        int start = (page-1)*rows;
        Page p = new Page(start,rows,s);
		Map map = new HashMap();
		try{
			List<Staff> list = staffService.list(p);
			Integer count = staffService.count(s);
			log.info(list);
			log.info(count);
			
			map.put("total",count );//total键 存放总记录数，必须的  
			map.put("rows",list);//rows键 存放每页记录 list 
			for (Staff staff : list) {
				log.info(staff);
			}
			
		}catch(Exception e){
			log.error(getTrace(e));
			map.put("meg", "失败！");
			map.put("status", "0");
		}
		
	    return map;  
	  }
	
	@ResponseBody
	//@RequestMapping(value = "/page.saveOrUpdateStaff.ashx")
	public String saveOrUpdateStaff(Staff staff) {
		try{
			if(staff.getsId()==-1){
				log.info("增加staff成功");
				log.info(staff);
				staff.setsId(null);
				staff.setsDeptId(1);
				staffService.insert(staff);
			}else{
				log.info("修改staff成功");
				log.info(staff);
				staff.setsDeptId(1);
				staffService.update(staff);

			}
			
		}catch(Exception e){
			log.error(getTrace(e));
			return "fail";
		}
		
		
	    return "success";  
	  }
	


	

}
